export default {
    getCartLength(state){
        return state.cartList.length
    },
    getCartCheckLength(state){
        return state.cartList.reduce((count,item)=>{
            if(item.checked){
                count++
            }
            return count
        },0)
    },
    getCartList(state){
        return state.cartList
    },
    isCheckedAll(state,getters){
        return getters.getCartLength > 0 && state.cartList.every(item=>{
            return item.checked
        })
    },
    totalPrice(state){
        const total = state.cartList.reduce((total,item)=>{
            if(item.checked){
                total+=parseFloat(item.price)*parseInt(item.counter)
            }
            return total
        },0)
        return "￥"+total.toFixed(2)
    }
}